package logic

import (
	"context"
	"errors"
	"study-go-zero/model_study/user/api/internal/svc"
	"study-go-zero/model_study/user/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type LoginLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginLogic {
	return &LoginLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *LoginLogic) Login(req *types.UserLoginResquest) (resp string, err error) {
	//res, err := l.svcCtx.UserModel.Insert(l.ctx, &model.User{
	//	Username: "张三",
	//	Password: "123456",
	//})

	user, err := l.svcCtx.UserModel.FindOneByUsernameAndPassword(l.ctx, req.Username, req.Password)

	if err != nil {
		return "", errors.New("账号或密码错误")
	}
	return user.Username, nil
}
